/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.swta.freezay.database.dbEntities;

import de.swta.freezay.database.JPAController;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Christian
 */
@Entity
@Table(name = "ITEM_PACKAGE")
@NamedQueries({@NamedQuery(name = "ItemPackage.findAll", query = "SELECT i FROM ItemPackage i"), @NamedQuery(name = "ItemPackage.findByPackageId", query = "SELECT i FROM ItemPackage i WHERE i.itemPackagePK.packageId = :packageId"), @NamedQuery(name = "ItemPackage.findByItemId", query = "SELECT i FROM ItemPackage i WHERE i.itemPackagePK.itemId = :itemId"), @NamedQuery(name = "ItemPackage.findByItemCount", query = "SELECT i FROM ItemPackage i WHERE i.itemCount = :itemCount")})
public class ItemPackage implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ItemPackagePK itemPackagePK;
    @Basic(optional = false)
    @Column(name = "ITEM_COUNT")
    private int itemCount;
    @JoinColumn(name = "ITEM_ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Item item;
    @JoinColumn(name = "PACKAGE_ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Package package1;

    public ItemPackage() {
    }

    public ItemPackage(ItemPackagePK itemPackagePK) {
        this.itemPackagePK = itemPackagePK;
    }

    public ItemPackage(ItemPackagePK itemPackagePK, int itemCount) {
        this.itemPackagePK = itemPackagePK;
        this.itemCount = itemCount;
    }

    public ItemPackage(int packageId, int itemId) {
        this.itemPackagePK = new ItemPackagePK(packageId, itemId);
    }

    public ItemPackage(int packageId, int itemId, int itemCount) {
        this.itemPackagePK = new ItemPackagePK(packageId, itemId);
        this.item = JPAController.ItemJpaController.findItem(itemId);
        this.package1 = JPAController.PackageJpaController.findPackage(packageId);
        this.itemCount = itemCount;
    }

    public ItemPackagePK getItemPackagePK() {
        return itemPackagePK;
    }

    public void setItemPackagePK(ItemPackagePK itemPackagePK) {
        this.itemPackagePK = itemPackagePK;
    }

    public int getItemCount() {
        return itemCount;
    }

    public void setItemCount(int itemCount) {
        if (itemCount >= 0) {
            this.itemCount = itemCount;
        }
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public Package getPackage1() {
        return package1;
    }

    public void setPackage1(Package package1) {
        this.package1 = package1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (itemPackagePK != null ? itemPackagePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ItemPackage)) {
            return false;
        }
        ItemPackage other = (ItemPackage) object;
        if ((this.itemPackagePK == null && other.itemPackagePK != null) || (this.itemPackagePK != null && !this.itemPackagePK.equals(other.itemPackagePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "de.swta.freezay.database.dbEntities.ItemPackage[itemPackagePK=" + itemPackagePK + "]";
    }

}
